package filerw;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.junit.jupiter.api.Test;

public class FileReadWriter {
	
	@Test
	public void write() throws IOException {
		File f = new File("names.txt");
		//1.创建字符输出流,默认覆盖写入文件,如果第二个参数是true就会追加往文件中写入
		FileWriter w = new FileWriter(f,true);
		//2.写内容,String,char[]
		w.write("哈哈");
		//3.刷新
		w.flush();
		//4.关闭
		w.close();
	}
	
	@Test
	public void read() throws IOException {
		//1.创建字符输入流
		FileReader r = new FileReader("names.txt");
		//2.读取
		char[] content = new char[100];
		r.read(content);
		//3.关闭流
		r.close();
		
		System.out.println(content);
	}
}
